﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using EnvDTE;
using EnvDTE80;
using Microsoft.VisualStudio.CommandBars;
using stdole;

namespace ClassGenerator
{
    public class IconUtils
    {
        public static void AddCommandIcon(CommandBarButton control, String iconFile)
        {
            SetControlPicture(control, iconFile);
        }              
                
        public static void SetControlPicture(CommandBarButton button, string fileName)
        {
            Bitmap b = new Bitmap(fileName);
            button.Picture = CreatePictureDisp(b);
        }
               
        protected static StdPicture CreatePictureDisp(Image image)
        {
            return (StdPicture)ImageConverter.GetIPictureDispFromImage(image);
        }
    }

    class ImageConverter : AxHost
    {
        // Methods
        internal ImageConverter() : base("52D64AAC-29C1-CAC8-BB3A-115F0D3D77CB")
        {
        }
        
        public static IPictureDisp GetIPictureDispFromImage(Image image)
        {
            return (IPictureDisp)AxHost.GetIPictureDispFromPicture(image);
        }
    }
}